//package com.netprovider.user.service.baseinfo;
//
//import java.io.IOException;
//
//import javax.ws.rs.container.ContainerRequestContext;
//import javax.ws.rs.container.ContainerRequestFilter;
//import javax.ws.rs.core.Response;
//
//import org.apache.cxf.common.util.Base64Exception;
//import org.apache.cxf.common.util.Base64Utility;
//
//public class AuthenticationHandler implements ContainerRequestFilter {
// 
//    @Override
//    public void filter(ContainerRequestContext requestContext) throws IOException {
//        String authorization = requestContext.getHeaderString("Authorization");
//        String[] parts = authValues.authorization(" ");
//        if (parts.length != 2 || !"Basic".equals(parts[0])) {
//            requestContext.abortWith(createFaultResponse());
//            return;
//        }
//         
//        String decodedValue = null;
//        try {
//            decodedValue = new String(Base64Utility.decode(parts[1]));
//        } catch (Base64Exception ex) {
//            requestContext.abortWith(createFaultResponse());
//            return;
//        }
//        String[] namePassword = decodedValue.split(":"); 
//        if (isAuthenticated(namePassword[0], namePassword[1])) {
//            // let request to continue
//        } else {
//            // authentication failed, request the authetication, add the realm name if needed to the value of WWW-Authenticate 
//            requestContext.abortWith(Response.status(401).header("WWW-Authenticate", "Basic").build());
//        }
//    }
//    private Response createFaultResponse() {
//        return Response.status(401).header("WWW-Authenticate", "Basic realm=\"service.com\"").build();
//    }
// }